package com.lesso.zgs.sunflower.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.core.ApiResponse;
import com.lesso.zgs.sunflower.pojo.dto.DeviceDTO;
import com.lesso.zgs.sunflower.pojo.dto.DeviceQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.DeviceVO;
import com.lesso.zgs.sunflower.service.IDeviceService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备基础信息 前端控制器
 * </p>
 *
 * @author zgs
 * @since 2025-07-03
 */
@RestController
@RequestMapping("/base/device")
public class DeviceController {
    @DubboReference
    private IDeviceService deviceService;

    @PostMapping
    public ResponseEntity<Integer> save(@RequestBody DeviceDTO dto) {
        return ResponseEntity.ok(deviceService.save(dto));
    }

    @RequestMapping("/{id}")
    public ResponseEntity<DeviceDTO> getById(@PathVariable Long id) {
        return ResponseEntity.ok(deviceService.getById(id));
    }

    @PutMapping
    public ResponseEntity<Integer> update(@RequestBody DeviceDTO dto) {
        return ResponseEntity.ok(deviceService.update(dto));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> delete(@PathVariable Long id) {
        return ResponseEntity.ok(deviceService.delete(id));
    }

    @GetMapping("/page")
    public ApiResponse<Page<DeviceVO>> page(DeviceQueryDTO dto) {
        return ApiResponse.ok("success", deviceService.page(dto));
    }
} 